package view;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JButton;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.concurrent.TimeUnit;

import javax.swing.JLabel;

import controls.Connection;

public class InfoPanel extends JPanel {
	ImagePanel contentPane;
	JButton btPlay, btOption, btUndo, btAbout, btQuit;
	JOptionPane exitConfirm;
	JLabel lbTimeRemain;
	PlayPanel playPanel;
	Connection connection;
	private final boolean HOST = true;

	public InfoPanel(final PlayPanel playPanel) {
		this.playPanel = playPanel;
//		this.connection = connection;
		playPanel.disableAll(true);
		contentPane = new ImagePanel(Toolkit.getDefaultToolkit().createImage(
				"images/contentbg.png"));
		btPlay = new JButton(new ImageIcon("images/play.png"));
		btPlay.setBorderPainted(false);
		btPlay.setFocusPainted(false);
		btPlay.setContentAreaFilled(false);
		btPlay.setBounds(0, 200, 200, 30);
		ActionListener playlner = new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				btPlay.setIcon(new ImageIcon("images/stop.png"));
				playPanel.disableAll(false);
			}
		};
		btPlay.addActionListener(playlner);

		btUndo = new JButton(new ImageIcon("images/undo.png"));
		btUndo.setBorderPainted(false);
		btUndo.setFocusPainted(false);
		btUndo.setContentAreaFilled(false);
		btUndo.setBounds(0, 250, 200, 30);

		btOption = new JButton(new ImageIcon("images/option.png"));
		btOption.setBorderPainted(false);
		btOption.setFocusPainted(true);
		btOption.setContentAreaFilled(false);
		btOption.setBounds(0, 300, 200, 30);

		btAbout = new JButton(new ImageIcon("images/about.png"));
		btAbout.setBorderPainted(false);
		btAbout.setFocusPainted(false);
		btAbout.setContentAreaFilled(false);
		btAbout.setBounds(0, 350, 200, 30);

		btQuit = new JButton(new ImageIcon("images/quit.png"));
		btQuit.setBorderPainted(false);
		btQuit.setFocusPainted(false);
		btQuit.setContentAreaFilled(false);
		btQuit.setBounds(0, 400, 200, 30);

		btQuit.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				int n = JOptionPane.showConfirmDialog(null,
						"Are you attempting to exit?", "Confirm exit",
						JOptionPane.YES_NO_OPTION);
				if (n == 0)
					System.exit(3);
			}
		});

		lbTimeRemain = new JLabel("", JLabel.CENTER);
		lbTimeRemain.setFont(new Font("Arial", Font.BOLD, 30));
		lbTimeRemain.setForeground(Color.WHITE);
		lbTimeRemain.setBounds(0, 450, 200, 30);
		lbTimeRemain.setText("0:20");

		contentPane.setLayout(null);
		contentPane.add(btPlay);
		contentPane.add(btUndo);
		contentPane.add(btOption);
		contentPane.add(btAbout);
		contentPane.add(btQuit);
		contentPane.add(lbTimeRemain);

		setLayout(new BorderLayout());
		setPreferredSize(new Dimension(200, 400));
		add((contentPane), BorderLayout.CENTER);
	}

	public boolean getHost() {
		return HOST;
	}
}
